<?php
class ReportsController extends AppController {

	var $name = 'Reports';
	var $helpers = array('Html','Javascript', 'Ajax');
	var $uses=array('Chiphi','P','Ctrinh','Zphieutien',
		'Quyetdinh','Chudaut','Dvthicong',
		'Nguonvon','Tien','Zchudtnguonvon');
	
	
	/****
	** dap ung cho chuc nang 16 theo hop dong
	thong the co cau kinh phi theo moc thoi gian
	*/
	function tke_thgian(){
		//$kqs=array();
		//$ngaybd=date('Y-m-d');
		//$ngaykt=date('Y-m-d');
		if(!empty($_POST['ngaybd'])){
			$ngaybd=$_POST['ngaybd'];
			$ngaykt=$_POST['ngaykt'];

			$kqs=$this->Zphieutien->find('all',array(
				'conditions'=>array('P.ngaylap between ? and ?'=>array($ngaybd,$ngaykt)),
				'group'=>array('id', 'tenchudautu'),
				'fields'=>array('id', 'tenchudautu','count(*) as soct','sum(tongphi) as phi')));
			$tong=$this->Zphieutien->find('first',array(
				'conditions'=>array('P.ngaylap between ? and ?'=>array($ngaybd,$ngaykt)),
				'fields'=>array('sum(tongphi) as tphi')));
			$tong=$tong[0]['tphi'];
		}
	
		
		$this->set(compact('kqs','tong'));
	}
	
	
}
